﻿<%@ Control Language="C#" ClassName="CollectionInfoControl" CodeFile="CollectionInfo.aspx.cs" Inherits="CollectionInfo" %>
<script RunAt="server">
protected int DaysTillPayOff = 0;
public void UpdateParameters() { dsCollInfo.SelectParameters.UpdateValues(Context, dsCollInfo); }
UOX _uox = null;
UOX uox { get { if (_uox != null)return _uox; return _uox = new UOX(); } }
	
protected override void OnInit(EventArgs e) {
	base.OnInit(e);
	fvCollectionInfo.ItemCreated += new EventHandler(fvCollectionInfo_ItemCreated);
}

protected void CollectionInfo_DataBinding(object sender, EventArgs e) {
	HtmlGenericControl gc = sender as HtmlGenericControl;
	uox.applID = Lib.MakeInt(Lib.GetProperty(this,"LoanID"));
	DataRowView drv = fvCollectionInfo.DataItem as DataRowView;
	gc.InnerHtml = Data.SQL.XmlInnerText(drv.Row);
}
	
protected void dsCBs_Selected(object sender, ObjectDataSourceStatusEventArgs e) {
	DataView dv = e.ReturnValue as DataView;
	if (dv != null && dv.Count > 1 && Lib.MakeInt(dv[1]["BorrowerID"]) == 0) {
		try {
			Data.SQL.ExecuteSP("[usix].[s_Export_Short_AddOn]", "", 0, Lib.GetProperty(this, "LoanID"));
		} catch (Exception exc) {
			Dimok.Web.UI.JS.RegisterClientScriptBlock(this, "alert('" + Dimok.Exceptions.ClientException.GetMessages(exc).Replace("'", "\\'").Replace(Environment.NewLine, "\\n").Replace("\r", "") + "');");
			return;
		}
		Dimok.Web.UI.JS.RegisterClientScriptBlock(this, "btnRefresh().click()");
	}
}
protected override void OnPreRender(EventArgs e) {
	dsCollInfo.SelectList += "," + DaysTillPayOff + " AS PODays,ISNULL([Total Principal], 0) + ISNULL((DSLP+" + DaysTillPayOff + ") * PerDiem, 0) + ISNULL(LateBalance, 0) + ISNULL([NSF Balance], 0) AS PayOff";
	base.OnPreRender(e);
}

protected void fvCollectionInfo_ItemCreated(object sender, EventArgs e) {
	FormViewEx fv = sender as FormViewEx;
	DataView dv = fv.DataItem as DataView;
}
protected void BuyBackStatus_Change(object sender, EventArgs e) {
	DropDownList ddl = (DropDownList)sender;
	int stateFromID = int.Parse(ddl.Attributes["StatusFromID"]);
	int loanID = (int)Lib.GetProperty(Page, "LoanID");
	Dimok.Aspx.Manager.UOX.BuyBackClass bb = new Dimok.Aspx.Manager.UOX.BuyBackClass(loanID);
	bb.SetStatus(ddl.SelectedValue);
}

void txtPOD_TextChanged(object sender, EventArgs e) {
	DaysTillPayOff = Lib.MakeInt(((ITextControl)sender).Text);
	fvCollectionInfo.RequiresDataBinding = true;
}
protected override void SetStateValues(Hashtable values) {
	base.SetStateValues(values);
	DaysTillPayOff = Lib.MakeInt(values[ClientID + ".DaysTillPayOff"]);
}
protected override void GetStateValues(Hashtable values) {
	base.GetStateValues(values);
	values[ClientID + ".DaysTillPayOff"] = DaysTillPayOff;
}
void ScriptLocal(object sender, EventArgs e) {
	Dimok.Web.UI.JS.ScriptLocalID(Page, sender as Control);
}
void ShowLetter(object sender, CommandEventArgs e) {
	ListControl ddlLetters = ((Control)sender).Parent.FindControl("ddlLetters") as ListControl;
	Response.Redirect("/Manager/Documents/Letter.aspx?Letter=" + ddlLetters.SelectedValue + "&Filter=ApplID=" + e.CommandArgument , true);
	Response.End();
}

</script>
<style>
</style>
<UI:FormViewEx ID="fvCollectionInfo" cssclass="CollectionCard" DataSourceID="dsCollInfo" DefaultMode="ReadOnly" runat="server">
	<ItemTemplate>
		<table CellPadding="0" CellSpacing="0">
			<tr>
			<DS:Collection_BorrowersDataSource ID="dsCBs" OnSelected="dsCBs_Selected" runat="server">
				<SelectParameters>
				<asp:ControlParameter ControlID="dsCBs"  Name="UsixID" PropertyName="Page.UsixID" Type="String" />
				<asp:ControlParameter ControlID="dsCBs" Name="CompanyID" PropertyName="Page.CompanyID" Type="Int32" />
				</SelectParameters>
			</DS:Collection_BorrowersDataSource>
			<asp:Repeater DataSourceID="dsCBs" runat="server">
				<ItemTemplate>
				<td>
		<table class="Borrower Big" BgColor="#FFF9E5" CellPadding="0" CellSpacing="0">
			<col style="padding-left:2px" />
			<tr>
				<td style="border:1 solid lightgrey"><span><%#Eval("Name")%></span></td>
			</tr>
			<tr>
				<td style="cursor:hand" oncontextmenu='return showSSNMenu(<%#"\""+Eval("ApplID")+"\",\""+Eval("SSN")+"\""%>)'
						title="Right Click for Menu"
						onclick='goPeopleSearch(<%#Eval("SSN","\"{0}\"")%>)'>
					<%#Lib.FormatSSN(Eval("SSN"))+(Lib.MakeInt(Eval("Pos"))==0?"[<b>"+Lib.GetProperty(this,"UsixID")+"</b>]":"")%>
				</td>
			<tr>
				<td style="border:none">
					<input id="txaPhoneHome"
						onchange='return changeHome(this.value,<%#Lib.FormatPhone(Eval("BorrowerID"))%>)' value='<%#Lib.FormatPhone(Eval("PhoneHome"), "N/H")%>' />
					<span title='Click to dial <%#Eval("PhoneHome","\"{0}\"")%>' class="Dial" onclick='dial("","",this.parentElement.all("txaPhoneHome").value)'>
						Home
					</span>
				</td>
			<tr>
				<td style="border:none">
					<input id="txaPhoneWork"
						onchange='return changeWork(this.value,<%#Lib.FormatPhone(Eval("BorrowerID"))%>)'value='<%#Lib.FormatPhone(Eval("PhoneWork"), "N/W")%>' />
					<span title='Click to dial <%#Eval("PhoneWork","\"{0}\"")%>' class="Dial" onclick='dial("","",this.parentElement.all("txaPhoneWork").value)'>
						Work
					</span>
				</td>
			<tr>
				<td style="border:none">
					<input id="txaPhoneCell"
						onchange='return changeCell(this.value,<%#Lib.FormatPhone(Eval("BorrowerID"))%>)' value='<%#Lib.FormatPhone(Eval("PhoneCell"), "N/C")%>' />
					<span title='Click to dial <%#Eval("PhoneCell","\"{0}\"")%>' class="Dial" onclick='dial("","",this.parentElement.all("txaPhoneCell").value)'>
						Cell
					</span>
				</td>
			<tr>
				<td>
					<input style="overflow:visible"  onchange='return changeStreet(this.value,<%#Eval("BorrowerID")%>)' value='<%#Eval("Street")%>' />
					<span  title='<%#Eval("Street","Click to see map for:{0}")%>' class="Dial" onclick='showGoogle(<%#Eval("Street","\"{0}"+Eval("Zip",",{0}")+"\"")%>)'>G</span>
				</td>
			<tr>
				<td style="border:none" Align="right">
					<input style="overflow-x:visible" Size="3" onchange='return changeCity(this.value,<%#Eval("BorrowerID")%>)' value='<%#Eval("CityName")%>' />,
					<input style="overflow-x:visible" Size="1" onchange='return changeState(this.value,<%#Eval("BorrowerID")%>)' value='<%#Eval("StateCode")%>' />
					<input style="overflow-x:visible" Size="3" onchange='return changeZip(this.value,<%#Eval("BorrowerID")%>)' value='<%#Eval("Zip")%>' />
				</td>
			</tr>
		</table>
					</td>
					<td class="vbar"></td>
				</ItemTemplate>
			</asp:Repeater>
			<td>
				<table Class="Borrower Big" style="" CellPadding="0" CellSpacing="0">
					<colgroup span="2" Align="left" /><colgroup span="1" /><colgroup span="2" Align="left"></colgroup>
					<tr><th title="Days Past Due">DPD</th><th>:</th><td><%#Eval("DPD")%></td>
							<td rowspan="10" class="vbar"></td>
							<th align="left">Curr Bal</th><th>:</th><td><span><%#Eval("Total Principal", "{0:c}")%></span>
							<td rowspan="10" class="vbar"></td>
							<td colspan="3" onclick='showTitle(<%#Eval("VIN","\"{0}\"")%>)' class="car" Align="left"><%#Eval("VIN")%></td>
					<tr><th title="Past Due Amount">PD$</th><th>:</th><td><span><%#Eval("PastDue", "{0:n2}")%></span>
							<th align="left">Pay Off in <asp:TextBox ID="txtPOD" OnTextChanged="txtPOD_TextChanged" AutoPostBack="true" Text='<%#Eval("PODays")%>' style="width:2ex;vertical-align:middle" onclick="event.cancelBubble=true;" runat="server"></asp:TextBox></th><th>:</th><td><span><%#Eval("PayOff", "{0:c}")%></span>
							<td colspan="3" class="car" Align="left"><%#Eval("Car Year", "{0:00}") + " " + Eval("Make") + " " + Eval("Model")%></td>
					<tr><th>Late Chg</th><th>:</th><td><span><%#Eval("LateBalance", "{0:c}")%></span>
							<th align="left">Pmt Amt</th><th>:</th><td><span><%#Eval("Payment Amount", "{0:c}")%></span>
							<td colspan="3" class="car" Align="left"><%#Eval("Dealer Code")%>:<%#Eval("Dealer")%></td>
					<tr><th>Par Pmt</th><th>:</th><td><span><%#Eval("Partial Payment", "{0:c}")%></span>
							<th align="left">Pmts Made</th><th>:</th><td style="border:none" ><span><%#Eval("PaymentsMade", "{0:n0}") + (Eval("Pymnt Schedule") + "" == "M" ? "" : "[" + Eval("PaymentsMadeM", "{0:n0}") + "mos]")%></span>
																 <b>Rem:</b><span><%#Eval("# Pmts Remaining", "{0:n0}") + (Eval("Pymnt Schedule") + "" == "M" ? "" : "[" + Eval("# Pmts RemainingM", "{0:n0}") + "mos]")%></span>
							<td colspan="3" class="car" Align="left"><%#Lib.FormatPhone(Eval("DealerPhone"), "N/Ph")%></td>
					<tr><th>Last Paid</th><th>:</th><td><span><%#Eval("Last Payment Date", "{0:MM/dd/yyyy}")%></span>
							<th align="left"># Pmts</th><th>:</th><td><%#Eval("# of Payments", "{0:n0}") + Eval("Pymnt Schedule") + (Eval("Pymnt Schedule") + "" == "M" ? "" : "[" + Eval("# of PaymentsM", "{0:n0}") + "mos]")%></td>
							<th NoWrap>Amt Fin</th><th>:</th><td><%#Eval("Amt_ Fin__Disc_ Amt", "{0:c}")%></td>
					<tr><th>Next Due</th><th>:</th><td><span><%#Eval("Next Payment Date", "{0:MM/dd/yyyy}")%></span>
							<th align="left">Per Diem</th><th>:</th><td><span><%#Eval("PerDiem", "{0:n2}")%></span>
							<th>APR</th><th>:</th><td><%#Eval("APR")%>%</td>
					<tr><th>1st Due</th><th>:</th><td colspan="5">
							<span>
							<%#Eval("1st_ Payment Date", "{0:MM/dd/yyyy}")%>
							<asp:PlaceHolder Visible='<%#(int)Eval("HasDeferment")==1%>' runat="server">
								<%# Eval("FirstPaymentDateCalc", "<FONT COLOR='DARKGREEN'><B>[{0:MM/dd/yyyy}]</B></FONT>")%>
								<ajaxtk:HoverMenuExtender TargetControlID="lblDeferments" PopupControlID="pnlDeferments" HoverDelay="300" runat="server" />
								<asp:Label Text='Deferments' runat="server" ID="lblDeferments" style="font-weight:bold;color:DarkGreen" />
								<asp:Panel ID="pnlDeferments" runat="server" BackColor="Wheat" BorderColor="DarkGoldenrod" BorderStyle="Solid" BorderWidth="0px">
								<div style="padding:0px 3px;border:solid 1px DarkGoldenrod">
								<asp:Repeater ID="rptDeferments" runat="server" DataSourceID="dsDeferments">
								<ItemTemplate>
									<%#Eval("Date","{0:d}")+Eval("DeferedDays","({0})")%><br />
								</ItemTemplate>
								</asp:Repeater>
								</div>
								</asp:Panel>
								<asp:LinqDataSource ContextTypeName="Data.LINQ.MotoBank" TableName="reports_V_Deferments" runat="server"
										 Where="UsixID=@UsixID AND CompanyID_Raw=@CompanyID" ID="dsDeferments">
								<WhereParameters>
									<asp:ControlParameter ControlID="dsDeferments"  Name="UsixID" PropertyName="Page.UsixID" Type="String" />
									<asp:ControlParameter ControlID="dsDeferments" Name="CompanyID" PropertyName="Page.CompanyID" Type="Int32" />
								</WhereParameters>
									
								</asp:LinqDataSource>
							</asp:PlaceHolder>
							</span>
							</td>
				</table>
			</td>
			<td style="border-style:double;border-color:LightGrey;border-width:1px"></td>
			</tr></table>
			<DS:Collection_StatsDataSource ID="dsPTP" runat="server">
			<SelectParameters>
				<asp:ControlParameter ControlID="dsPTP"  Name="LoanID" PropertyName="Page.LoanID" Type="Int32" />
			</SelectParameters>
			</DS:Collection_StatsDataSource>
			<DS:StateFlowNextStatesDataSource ID="dsBBStatuses" StateFromID='<%#Eval("StatusID_BuyBack")%>' runat="server" />
			<table><tr VAlign="top">
				<td>
					<asp:GridView DataSourceID="dsPTP" runat="server" CssClass=GridView RowStyle-HorizontalAlign="Center"></asp:GridView>
				</td>
				<td Align="center"><b>Customer Time</b><br /><%#Eval("LocalTime", "{0:hh:mm tt(" + Eval("TimeZone") + ")}")%></td>
				<td id="tdCollectionExpiration" style="cursor:hand" title="Click to reset session timer." align="center">
				</td>
				<td Align="center">
<input id="btnShowLetter" type="button" OnClick='if( !ddlLetters.value )return alert(SELECT_LETTER_MSG);showCollectionLetters(ddlLetters.value,<%#Eval("ApplID","\"Filter=ApplID={0}\"")%>);setTimeout(function(){btnRefresh().click();},3000)' style="" title="Click to generate Letters for selected list" value="Show Letter" />
<br />
<select ID="ddlLetters">
<option  Value="" >Select ...</option>
<option Value="Welcome">Welcome</option>
<option Value="Delinquency.PastDue_02_06">Past Due(2-6)</option>
<option Value="Delinquency.PastDue_15_20">1st Letter(15-20)</option>
<option Value="Delinquency.PastDue_25_29">2st Letter(25-29)</option>
<option Value="Delinquency.PastDue_31_35">Serious Letter(31-35)</option>
<option Value="Delinquency.PastDue_36">Final Letter(36)</option>
<option Value="Delinquency.BrokenPromise">Broken Promise</option>
<option Value="Delinquency.NSF">N.S.F.</option>
<option Value="Invoice">Invoice</option>
</select>
				</td>
				<td>
					Bankruptcy<br />
					<UI:LoanStatus DataSrc="XmlCollectionInfo" DataFld="StatusID_BK" IDName="LoanID" StatusFromID='<%#Eval("StatusID_BK")%>' WSMethod="BKStatus" runat="server" />
				</td>
				<td>
					Collection Status<br />
					<UI:LoanStatus DataSrc="XmlCollectionInfo" DataFld="StatusID_Collection" IDName="LoanID" StatusFromID='<%#Eval("StatusID_Collection")%>' Width="100%" Rows="2" WSMethod="CollectionStatus" runat="server" />
				</td>
				<td>
					Repossession Status<br />
					<UI:LoanStatus DataSrc="XmlCollectionInfo" DataFld="StatusID_Repo" IDName="LoanID" StatusFromID='<%#Eval("StatusID_Repo")%>' Width="100%" Rows="2" WSMethod="RepoStatus" runat="server" />
				</td>
				<td>
					Buy Back Status<br />
					<UI:LoanStatus ID="LoanStatus1" DataSrc="XmlCollectionInfo" DataFld="StatusID_BuyBack" IDName="LoanID" StatusFromID='<%#Eval("StatusID_BuyBack")%>' WSMethod="BuyBackStatus" runat="server" />
				</td>
			</tr></table>
			<UI:PlaceHolderJS runat="server">
				<XML id="XmlCollectionInfo" ondatabinding="CollectionInfo_DataBinding" runat="server"><%#Eval("LoanID")%></XML>
			</UI:PlaceHolderJS>
	</ItemTemplate>
</UI:FormViewEx>
<DS:CollectionInfoDataSource id="dsCollInfo" SelectList="*, CASE [1st_ Payment Date] WHEN FirstPaymentDateCalc THEN 0 ELSE 1 END HasDeferment" EmtyRowPolicy="None" runat="server">
	<SelectParameters>
	<asp:ControlParameter ControlID="dsCollInfo"  Name="UsixID" PropertyName="Page.UsixID" Type="String" />
	<asp:ControlParameter ControlID="dsCollInfo" Name="CompanyID" PropertyName="Page.CompanyID" Type="Int32" />
	</SelectParameters>
</ds:CollectionInfoDataSource>
<script>

</script>